from odoo import fields,models,api
from odoo.exceptions import UserError

OPEN_HOURS_CATE=[('every_day','每天'),('one','周一'),('two','周二'),('three','周三'),('four','周四'),('five','周五'),('six','周六'),('seven','周日')]


class PeOpeningHours(models.Model):
    _name = 'pe.opening.hours'
    _description = '营业时间段'

    name=fields.Char(string='名称')
    pe_merchant_shop_id=fields.Many2one(string='主表',comodel_name='pe.merchant.shop')
    open_hours_cate=fields.Selection(string='类型',selection=OPEN_HOURS_CATE)
    start_date=fields.Float(string='开始时间')
    end_date=fields.Float(string='结束时间')
    is_rest_day=fields.Boolean(string='休息')


    @api.constrains('start_date','end_date')
    def _constraint_data(self):
        for record in self:
            if record.end_date<=record.start_date:
                raise UserError('请按照规定格式填写时间！')
